package com.fc.v2.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.v2.common.base.BaseService;
import com.fc.v2.common.support.ConvertUtil;
import com.fc.v2.mapper.auto.ApplyParticipatorMapper;
import com.fc.v2.model.auto.ApplyParticipator;
import com.fc.v2.model.auto.ApplyParticipatorExample;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.util.SnowflakeIdWorker;
import com.fc.v2.util.StringUtils;

/**
 * 课题主要参与者 ApplyParticipatorService
 * @Title: ApplyParticipatorService.java 
 * @Package com.fc.v2.service 
 * @author Archie_自动生成
 * @email ${email}
 * @date 2021-11-04 16:39:27  
 **/
@Service
public class ApplyParticipatorService implements BaseService<ApplyParticipator, ApplyParticipatorExample>{
	@Autowired
	private ApplyParticipatorMapper applyParticipatorMapper;
	
      	   	      	      	      	      	      	      	      	      	
	/**
	 * 立项分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<ApplyParticipator> list(Tablepar tablepar,ApplyParticipator applyParticipator,String proId){
	        ApplyParticipatorExample testExample=new ApplyParticipatorExample();
			//搜索
			if(StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
	        	testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
	        }else {//大搜索
	        	testExample.createCriteria().andProjectIdEqualTo(proId).andFinishIdIsNull();
	        }
			//表格排序
			//if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        //	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        //}else{
	        //	testExample.setOrderByClause("id ASC");
	        //}
	        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
	        List<ApplyParticipator> list= applyParticipatorMapper.selectByExample(testExample);
	        PageInfo<ApplyParticipator> pageInfo = new PageInfo<ApplyParticipator>(list);
	        return  pageInfo;
	 }

	/**
	 * 立项分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public PageInfo<ApplyParticipator> listEdit(Tablepar tablepar,ApplyParticipator applyParticipator,String proId,String applyId){
		ApplyParticipatorExample testExample=new ApplyParticipatorExample();
		//搜索
		if(StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
			testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
		}else {//大搜索
			testExample.createCriteria().andProjectIdEqualTo(applyId).andFinishIdEqualTo(proId);
		}
		//表格排序
		//if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
		//	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
		//}else{
		//	testExample.setOrderByClause("id ASC");
		//}
		PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
		List<ApplyParticipator> list= applyParticipatorMapper.selectByExample(testExample);
		PageInfo<ApplyParticipator> pageInfo = new PageInfo<ApplyParticipator>(list);
		return  pageInfo;
	}

	/**
	 * 结项分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public PageInfo<ApplyParticipator> listFinish(Tablepar tablepar,ApplyParticipator applyParticipator,String proId,String applyId){
		ApplyParticipatorExample testExample=new ApplyParticipatorExample();
		//搜索
		if(StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
			testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
		}else {//大搜索
			testExample.createCriteria().andProjectIdEqualTo(applyId).andFinishIdEqualTo(proId);
		}
		//表格排序
		//if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
		//	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
		//}else{
		//	testExample.setOrderByClause("id ASC");
		//}
		PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
		List<ApplyParticipator> list= applyParticipatorMapper.selectByExample(testExample);
		PageInfo<ApplyParticipator> pageInfo = new PageInfo<ApplyParticipator>(list);
		return  pageInfo;
	}

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=ConvertUtil.toListStrArray(ids);
			ApplyParticipatorExample example=new ApplyParticipatorExample();
			example.createCriteria().andIdIn(lista);
			return applyParticipatorMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public ApplyParticipator selectByPrimaryKey(String id) {
				
			return applyParticipatorMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(ApplyParticipator record) {
		return applyParticipatorMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 添加
	 */
	@Override
	public int insertSelective(ApplyParticipator record) {

		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());

		return applyParticipatorMapper.insertSelective(record);
	}

	/**
	 * 添加
	 */
	public int insertSelectiveFinish(ApplyParticipator record,String proId) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
		//添加项目id
		record.setProjectId(proId);
				
		return applyParticipatorMapper.insertSelective(record);
	}

	/**
	 * 添加
	 */
	public int insertSelectiveFinishApp(ApplyParticipator record,String proId,String applyId) {

		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
		//添加立项项目id
		record.setProjectId(applyId);
		//添加结项项目id
		record.setFinishId(proId);

		return applyParticipatorMapper.insertSelective(record);
	}
	
	@Override
	public int updateByExampleSelective(ApplyParticipator record, ApplyParticipatorExample example) {
		
		return applyParticipatorMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(ApplyParticipator record, ApplyParticipatorExample example) {
		
		return applyParticipatorMapper.updateByExample(record, example);
	}

	@Override
	public List<ApplyParticipator> selectByExample(ApplyParticipatorExample example) {
		
		return applyParticipatorMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(ApplyParticipatorExample example) {
		
		return applyParticipatorMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(ApplyParticipatorExample example) {
		
		return applyParticipatorMapper.deleteByExample(example);
	}
	
	/**
	 * 修改权限状态展示或者不展示
	 * @param applyParticipator
	 * @return
	 */
	public int updateVisible(ApplyParticipator applyParticipator) {
		return applyParticipatorMapper.updateByPrimaryKeySelective(applyParticipator);
	}


}
